/********************************************************************************
*                 Copyright (C) 2011 - Las Venturas Playground                  *
*                      http://iv-mp.nl | http://lvp-iv.com                      *
*                                                                               *
*    This program is free software: you can redistribute it and/or modify       *
*    it under the terms of the GNU General Public License as published by       *
*    the Free Software Foundation, either version 3 of the License, or          *
*    (at your option) any later version.                                        *
*                                                                               *
*    This program is distributed in the hope that it will be useful,            *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of             *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
*    GNU General Public License for more details.                               *
*                                                                               *
*    You should have received a copy of the GNU General Public License          *
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
*                                                                               *
*********************************************************************************
*                                                                               *
*  Las Venturas Playground - callbacks/onPlayerDeath.nut                        *
*                                                                               *
*  The onPlayerDeath callback is located here.                                  *
*                                                                               *
********************************************************************************/

/**
 * This event is called when a user was killed or killed somebody.
 *
 * @param playerid The playerid that was killed
 * @param killerid The playerid that killed.
 */
function onPlayerDeath (playerid,killerid, killervehicle)
{
    // He's dead, set isSpawned to false
    isSpawned[playerid] = false;
    
    if (killerid != INVALID_PLAYER_ID)
    {
        // Get the weapon ID the killer used.
        local killerWeapon = 0;
        if (getPlayerWeapon (killerid) != false) killerWeapon = getPlayerWeapon (killerid);
        
        // Inform everyone.
        sendMessageToAll (getPlayerName (playerid) + " has been killed by " + getPlayerName (killerid) + " (Weapon: " + weaponNames[killerWeapon] + ")", COLOR_RED);
        
        // Increment the amount of kills and deaths for the killer and the playerid.
        playerInfo[killerid].Kills++;
        playerInfo[playerid].Deaths++;
    }
    else
    {
        sendMessageToAll (getPlayerName (playerid) + " has died", COLOR_RED);
        
        // Increment the amount of deaths for the killed player.
        playerInfo[playerid].Deaths++;
    }
    return 1;
}

addEvent("playerDeath", onPlayerDeath);
